package logic

import (
	"context"
	"shop_srv/models"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowActivityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowActivityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowActivityLogic {
	return &ShowActivityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowActivityLogic) ShowActivity(in *shop.ShowActivityRequest) (*shop.ShowActivityResponse, error) {
	// todo: add your logic here and delete this line

	var a models.ActivityInfo

	models.DB.Table("goods").
		Select("activities.*,goods.title as goods_title,goods.stock as goods_stock").
		Joins("LEFT JOIN activities ON activities.goods_id=goods.id").
		Where("activities.id=?", in.ActivityId).
		Find(&a)

	return &shop.ShowActivityResponse{
		ActivityId:    int64(a.ID),
		GoodsTitle:    a.GoodsTitle,
		GoodsStock:    a.GoodsStock,
		ActivityPrice: float32(a.ActivityPrice),
		Progress:      a.Progress,
		Countdown:     a.Countdown,
	}, nil
}
